<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/blog/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://guodh.gitee.io/blog').hostname,
    root: '/blog/',
    scheme: 'Pisces',
    version: '7.7.1',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="为什么需要算法？  利用空间来降低时间复杂度。 有效的数据结构，依然能够解决一些极端问题。 以及面试！">
<meta property="og:type" content="article">
<meta property="og:title" content="数据结构和算法">
<meta property="og:url" content="https://guodh.gitee.io/blog/2022/04/17/2022/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E7%AE%97%E6%B3%95/index.html">
<meta property="og:site_name" content="蛋蛋的小屋">
<meta property="og:description" content="为什么需要算法？  利用空间来降低时间复杂度。 有效的数据结构，依然能够解决一些极端问题。 以及面试！">
<meta property="og:locale">
<meta property="og:image" content="https://guodhblog.oss-cn-hangzhou.aliyuncs.com/2022/%E7%99%BE%E4%B8%87%E8%81%8A%E5%A4%A9%E5%AE%A4%E6%9E%B6%E6%9E%84.jpeg?versionId=CAEQTBiBgID95MiHghgiIDM0MzIzNjcyMWI0OTQ2MjliNzNkYmFiOTgwNzBlMGVl">
<meta property="article:published_time" content="2022-04-17T01:29:07.000Z">
<meta property="article:modified_time" content="2022-04-20T02:41:22.556Z">
<meta property="article:author" content="RunningEgg">
<meta property="article:tag" content="技术">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://guodhblog.oss-cn-hangzhou.aliyuncs.com/2022/%E7%99%BE%E4%B8%87%E8%81%8A%E5%A4%A9%E5%AE%A4%E6%9E%B6%E6%9E%84.jpeg?versionId=CAEQTBiBgID95MiHghgiIDM0MzIzNjcyMWI0OTQ2MjliNzNkYmFiOTgwNzBlMGVl">

<link rel="canonical" href="https://guodh.gitee.io/blog/2022/04/17/2022/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E7%AE%97%E6%B3%95/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>数据结构和算法 | 蛋蛋的小屋</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">蛋蛋的小屋</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">来了就看看吧，没有刀剑只有故事</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-fw fa-user"></i>About</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-book">

    <a href="/blog/book/" rel="section"><i class="fa fa-fw fa-archive"></i>book</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://guodh.gitee.io/blog/2022/04/17/2022/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E7%AE%97%E6%B3%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="RunningEgg">
      <meta itemprop="description" content="写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="蛋蛋的小屋">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          数据结构和算法
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2022-04-17 09:29:07" itemprop="dateCreated datePublished" datetime="2022-04-17T09:29:07+08:00">2022-04-17</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2022-04-20 10:41:22" itemprop="dateModified" datetime="2022-04-20T10:41:22+08:00">2022-04-20</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>为什么需要算法？</p>
<ol>
<li>利用空间来降低时间复杂度。</li>
<li>有效的数据结构，依然能够解决一些极端问题。</li>
<li>以及面试！</li>
</ol>
<a id="more"></a>

<h2 id="数据结构"><a href="#数据结构" class="headerlink" title="数据结构"></a>数据结构</h2><table>
<thead>
<tr>
<th>数据结构</th>
<th>技巧</th>
<th>使用场景</th>
</tr>
</thead>
<tbody><tr>
<td>数组 Array</td>
<td>0. 数组是有位置概念<br/> 1. 位置交换<br/> 2. 指针取余<br/>  3. 多个指针<br/> 4. 排序</td>
<td>RingBuffer</td>
</tr>
<tr>
<td>链表 NodeList</td>
<td>1. 多使用指针：Pre指针，虚拟指针，头结点，尾结点<br/> 2. 维护了数据进入出去的有效性 <br/> 3. 快、慢指针找到中间节点，步长数量 <br/> 4. 关注cur指针，当前指针最后一定是需要走到 Null 为止</td>
<td>1. 跳跃表<br/>2. 内存空间管理</td>
</tr>
<tr>
<td>栈 Stack</td>
<td>1.先进先出<br/> 2.单调栈</td>
<td>堆栈</td>
</tr>
<tr>
<td>队列 Queue</td>
<td>消费者队列</td>
<td>LRU缓存</td>
</tr>
<tr>
<td>树 TreeNode</td>
<td>1.递归遍历、层序遍历<br/>2.二叉树、二叉搜索树、二叉搜索平衡树、红黑树、完全二叉树 <br/> 3.树高度、树深度、树宽度、路径</td>
<td>数据库B+Tree</td>
</tr>
</tbody></table>
<h3 id="作为数据结构应该要实现的几个功能"><a href="#作为数据结构应该要实现的几个功能" class="headerlink" title="作为数据结构应该要实现的几个功能"></a>作为数据结构应该要实现的几个功能</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> Struct &#123;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 添加节点</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">add</span><span class="params">()</span></span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 是否满</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">isFull</span><span class="params">()</span></span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 拿到节点</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">take</span><span class="params">()</span></span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 删除节点，同时保证数据结构内部的有效性</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">remove</span><span class="params">()</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="算法"><a href="#算法" class="headerlink" title="算法"></a>算法</h2><table>
<thead>
<tr>
<th>算法</th>
<th>特点</th>
</tr>
</thead>
<tbody><tr>
<td>二分查找</td>
<td>利用有序性来快速查找</td>
</tr>
<tr>
<td>滑动窗口</td>
<td>只关注局部的最大值，比DP更加简单和有效率</td>
</tr>
<tr>
<td>归并算法(自下而上)</td>
<td>拆分数组，从底层开始操作，mid + merge</td>
</tr>
<tr>
<td>快速排序</td>
<td>分治的思想和归并有点类似，分left和right进行排序</td>
</tr>
<tr>
<td>堆排序</td>
<td>维护局部的有序性</td>
</tr>
<tr>
<td>深度搜索DFS</td>
<td>和归并的概念不同，从上而下，类似于树的高度和深度</td>
</tr>
<tr>
<td>广度搜索BFS</td>
<td>顺序的去搜索，利用Queue的顺序性</td>
</tr>
<tr>
<td>回溯</td>
<td>回退的时候，将List的最尾端给Remove</td>
</tr>
<tr>
<td>动态规划DP</td>
<td>能够缓存结果，从上一个结果能推出下一个结果</td>
</tr>
<tr>
<td>前缀和</td>
<td>连续的子集合</td>
</tr>
</tbody></table>
<h2 id="位运算"><a href="#位运算" class="headerlink" title="位运算"></a>位运算</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">与:&amp;</span><br><span class="line">或:|</span><br><span class="line">取反:~</span><br><span class="line">异或:^   ---任何数和自己^，都是<span class="number">0</span></span><br><span class="line">左移右移:&lt;&lt; &gt;&gt;  ---左移右移的优先级，低于加减</span><br><span class="line">非:!</span><br></pre></td></tr></table></figure>


<h3 id="单调栈模板"><a href="#单调栈模板" class="headerlink" title="单调栈模板"></a>单调栈模板</h3><blockquote>
<p>给定一个整数数组 temperatures ，表示每天的温度，返回一个数组 answer ，其中 answer[i] 是指在第 i 天之后，才会有更高的温度。如果气温在这之后都不会升高，请在该位置用 0 来代替。<br><a href="https://leetcode-cn.com/problems/daily-temperatures/">https://leetcode-cn.com/problems/daily-temperatures/</a></p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;temperatures.length;i++) &#123;</span><br><span class="line">    <span class="keyword">while</span>(!deque.isEmpty() &amp;&amp; temperatures[deque.peek()] &lt; temperatures[i]) &#123;</span><br><span class="line">        <span class="keyword">int</span> oldIndex = deque.pop();</span><br><span class="line">        res[oldIndex] = i - oldIndex;</span><br><span class="line">    &#125;</span><br><span class="line">    deque.push(i);   </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="二分查找"><a href="#二分查找" class="headerlink" title="二分查找"></a>二分查找</h3><blockquote>
<p>寻找旋转排序数组中的最小值<br><a href="https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/">https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/</a></p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> left = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> right = nums.length -<span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span>(left &lt; right) &#123;</span><br><span class="line">    <span class="keyword">int</span> mid = (left + right) /<span class="number">2</span>;</span><br><span class="line">    <span class="keyword">if</span>(nums[mid] &gt; nums[right]) &#123;</span><br><span class="line">        left = mid +<span class="number">1</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        right = mid;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="滑动窗口"><a href="#滑动窗口" class="headerlink" title="滑动窗口"></a>滑动窗口</h3><blockquote>
<p>无重复字符的最长子串<br><a href="https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/">https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/</a></p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> right=<span class="number">0</span>;right &lt; charList.length ;right++) &#123;</span><br><span class="line">    <span class="keyword">while</span>(set.contains(charList[right])) &#123;</span><br><span class="line">        set.remove(charList[left]);</span><br><span class="line">        left++;</span><br><span class="line">    &#125;</span><br><span class="line">    set.add(charList[right]);</span><br><span class="line">    max = Math.max(max, right - left +<span class="number">1</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="前缀和"><a href="#前缀和" class="headerlink" title="前缀和"></a>前缀和</h3><blockquote>
<p>和为 K 的子数组</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;nums.length;i++) &#123;</span><br><span class="line">    sum = sum + nums[i];</span><br><span class="line">    <span class="keyword">if</span>(map.get(sum - k) != <span class="keyword">null</span>) &#123;</span><br><span class="line">        count = count + map.get(sum - k);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(map.get(sum) != <span class="keyword">null</span>) &#123;</span><br><span class="line">        map.put(sum, map.get(sum)+<span class="number">1</span>);</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        map.put(sum, <span class="number">1</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="常见的使用算法解决问题的场景"><a href="#常见的使用算法解决问题的场景" class="headerlink" title="常见的使用算法解决问题的场景"></a>常见的使用算法解决问题的场景</h2><blockquote>
<p>这类问题需要对问题本身有个理解<br>10亿 ~ 1 GB<br>100万 ~ 1 MB<br>当然，例如告诉你一条数据是 64B，那就是10亿 * 64Byte = 64 GB</p>
</blockquote>
<h3 id="统计用户是否在线、打卡记录"><a href="#统计用户是否在线、打卡记录" class="headerlink" title="统计用户是否在线、打卡记录"></a>统计用户是否在线、打卡记录</h3><blockquote>
<p>状态只有0或者1的场景<br>使用BitMap</p>
</blockquote>
<p>BitMap可以将数据量大大的降低，但是只能够表示0或者1的状态。</p>
<h3 id="大数据量的情况下，判断是否存在"><a href="#大数据量的情况下，判断是否存在" class="headerlink" title="大数据量的情况下，判断是否存在"></a>大数据量的情况下，判断是否存在</h3><blockquote>
<p>布隆过滤器</p>
</blockquote>
<p>基于BitMap，增加了多个Hash的算法，来实现是否0或者1的判断</p>
<h3 id="TopK情况"><a href="#TopK情况" class="headerlink" title="TopK情况"></a>TopK情况</h3><blockquote>
<p>数据量大，同时需要排序，但是单机内存数量有限制。</p>
</blockquote>
<p>先将数据划分到不同的服务器上，每个服务器进行堆排序，历史最小堆，每次移除最小值，然后多路合并结果，最终排序。</p>
<h3 id="在线用户数"><a href="#在线用户数" class="headerlink" title="在线用户数"></a>在线用户数</h3><blockquote>
<p>时序数据库 或者 Redis的Zset</p>
</blockquote>
<h3 id="弹幕系统设计"><a href="#弹幕系统设计" class="headerlink" title="弹幕系统设计"></a>弹幕系统设计</h3><img src="https://guodhblog.oss-cn-hangzhou.aliyuncs.com/2022/%E7%99%BE%E4%B8%87%E8%81%8A%E5%A4%A9%E5%AE%A4%E6%9E%B6%E6%9E%84.jpeg?versionId=CAEQTBiBgID95MiHghgiIDM0MzIzNjcyMWI0OTQ2MjliNzNkYmFiOTgwNzBlMGVl" alt="consumer.png" width="100%" height="100%"/>

<h3 id="排名系统"><a href="#排名系统" class="headerlink" title="排名系统"></a>排名系统</h3><p>使用Zset，同时基于城市或者UserId进行分库。对于查询操作，可以分库merge结果。</p>
<p>还需要解决深分页的问题。</p>
<blockquote>
<p><a href="https://blog.csdn.net/micro_hz/article/details/110919019">https://blog.csdn.net/micro_hz/article/details/110919019</a></p>
</blockquote>
<h3 id="发红包"><a href="#发红包" class="headerlink" title="发红包"></a>发红包</h3><h4 id="红包算法"><a href="#红包算法" class="headerlink" title="红包算法"></a>红包算法</h4><p>二倍均值法，【0 ~ 剩余金额 / 剩余人数 * 2】中随机，相对均匀</p>
<h4 id="红包表"><a href="#红包表" class="headerlink" title="红包表"></a>红包表</h4><p>主表：红包的总额拆分<br>子表：每个红包的金额、是否被抢、id等等，用行锁来减少竞争。</p>
<h3 id="红包雨"><a href="#红包雨" class="headerlink" title="红包雨"></a>红包雨</h3><p>数据库层面解决问题，引入TiDB等NewSQL的数据库，依托于计算和存储隔离的理念，通过智能的划分Regin，以及动态的分割Regin。</p>
<p>预分区，打散数据。</p>
<p>火山引擎采用自研架构的 Redis 系统提供缓存服务：通过集中化元数据存储，实现了节点和集群性能的海量扩展；通过异步和多线程 IO 优化，将热点数据打散和智能搬迁，大大降低 Redis 的长尾时延。</p>
<h3 id="评论系统"><a href="#评论系统" class="headerlink" title="评论系统"></a>评论系统</h3><p>在允许少部分丢数据的情况下，可以先放到Redis上，异步刷到 Mysql</p>
<h3 id="秒杀系统"><a href="#秒杀系统" class="headerlink" title="秒杀系统"></a>秒杀系统</h3><h3 id="常用手段"><a href="#常用手段" class="headerlink" title="常用手段"></a>常用手段</h3><ol>
<li>流量切割</li>
<li>异步化（Kafka、Rocketmq）</li>
<li>限流策略（Redis令牌桶）</li>
<li>批量提交</li>
<li>计算和存储分离，自动切割热点数据</li>
<li>读写分离</li>
</ol>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/%E6%8A%80%E6%9C%AF/" rel="tag"># 技术</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2022/04/16/2022/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" rel="prev" title="内存管理">
      <i class="fa fa-chevron-left"></i> 内存管理
    </a></div>
      <div class="post-nav-item"></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84"><span class="nav-number">1.</span> <span class="nav-text">数据结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%9C%E4%B8%BA%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%BA%94%E8%AF%A5%E8%A6%81%E5%AE%9E%E7%8E%B0%E7%9A%84%E5%87%A0%E4%B8%AA%E5%8A%9F%E8%83%BD"><span class="nav-number">1.1.</span> <span class="nav-text">作为数据结构应该要实现的几个功能</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AE%97%E6%B3%95"><span class="nav-number">2.</span> <span class="nav-text">算法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BD%8D%E8%BF%90%E7%AE%97"><span class="nav-number">3.</span> <span class="nav-text">位运算</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8D%95%E8%B0%83%E6%A0%88%E6%A8%A1%E6%9D%BF"><span class="nav-number">3.1.</span> <span class="nav-text">单调栈模板</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE"><span class="nav-number">3.2.</span> <span class="nav-text">二分查找</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3"><span class="nav-number">3.3.</span> <span class="nav-text">滑动窗口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%89%8D%E7%BC%80%E5%92%8C"><span class="nav-number">3.4.</span> <span class="nav-text">前缀和</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B8%B8%E8%A7%81%E7%9A%84%E4%BD%BF%E7%94%A8%E7%AE%97%E6%B3%95%E8%A7%A3%E5%86%B3%E9%97%AE%E9%A2%98%E7%9A%84%E5%9C%BA%E6%99%AF"><span class="nav-number">4.</span> <span class="nav-text">常见的使用算法解决问题的场景</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BB%9F%E8%AE%A1%E7%94%A8%E6%88%B7%E6%98%AF%E5%90%A6%E5%9C%A8%E7%BA%BF%E3%80%81%E6%89%93%E5%8D%A1%E8%AE%B0%E5%BD%95"><span class="nav-number">4.1.</span> <span class="nav-text">统计用户是否在线、打卡记录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%A4%A7%E6%95%B0%E6%8D%AE%E9%87%8F%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8"><span class="nav-number">4.2.</span> <span class="nav-text">大数据量的情况下，判断是否存在</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#TopK%E6%83%85%E5%86%B5"><span class="nav-number">4.3.</span> <span class="nav-text">TopK情况</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%9C%A8%E7%BA%BF%E7%94%A8%E6%88%B7%E6%95%B0"><span class="nav-number">4.4.</span> <span class="nav-text">在线用户数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%BC%B9%E5%B9%95%E7%B3%BB%E7%BB%9F%E8%AE%BE%E8%AE%A1"><span class="nav-number">4.5.</span> <span class="nav-text">弹幕系统设计</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%8E%92%E5%90%8D%E7%B3%BB%E7%BB%9F"><span class="nav-number">4.6.</span> <span class="nav-text">排名系统</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8F%91%E7%BA%A2%E5%8C%85"><span class="nav-number">4.7.</span> <span class="nav-text">发红包</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BA%A2%E5%8C%85%E7%AE%97%E6%B3%95"><span class="nav-number">4.7.1.</span> <span class="nav-text">红包算法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BA%A2%E5%8C%85%E8%A1%A8"><span class="nav-number">4.7.2.</span> <span class="nav-text">红包表</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BA%A2%E5%8C%85%E9%9B%A8"><span class="nav-number">4.8.</span> <span class="nav-text">红包雨</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AF%84%E8%AE%BA%E7%B3%BB%E7%BB%9F"><span class="nav-number">4.9.</span> <span class="nav-text">评论系统</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%A7%92%E6%9D%80%E7%B3%BB%E7%BB%9F"><span class="nav-number">4.10.</span> <span class="nav-text">秒杀系统</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E6%89%8B%E6%AE%B5"><span class="nav-number">4.11.</span> <span class="nav-text">常用手段</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">RunningEgg</p>
  <div class="site-description" itemprop="description">写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">89</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">tags</span>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="mailto:guodh_1@163.com" title="E-Mail → mailto:guodh_1@163.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">RunningEgg</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> v5.3.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">Theme – <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.7.1
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  















  

  

</body>
</html>
